#include "FileFormatter.h"
#include <sstream>
#include <iomanip>

FileFormatter::FileFormatter(const File& file)
{
	GenerateString(file);
}

FileFormatter::~FileFormatter()
{
}

void FileFormatter::GenerateString(const File& file)
{
	std::ostringstream stream;

	//Example formatted string:
	//drw-rw-rw-   1 user     group           0 Sep 27 06:49 filename\r\n"


	if (file.IsDirectory())
		stream << "d";
	else
		stream << "-";

	const Date& date = file.CreationDate();

	stream << "rwxr-xr-x ";
	stream << 1;
	stream << " user users ";

	if (file.IsDirectory())
		stream << 0;
	else
		stream << file.Size();
	stream << " ";
	stream << date.MonthString();
	stream << " ";
	stream << date.Day();
	stream << " ";
	stream << std::setfill('0') << std::setw(2) << date.Hour();
	stream << ":";
	stream << std::setfill('0') << std::setw(2) << date.Minute();
	stream << " ";
	stream << file.Alias();

	formattedString = stream.str();
}

const std::string& FileFormatter::FormattedString() const
{
	return formattedString;
}
